package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlMnetHost entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlMnetHost
 * @author MyEclipse Persistence Tools
 */

public class MdlMnetHostDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlMnetHostDAO.class);
	// property constants
	public static final String DELETED = "deleted";
	public static final String WWWROOT = "wwwroot";
	public static final String IP_ADDRESS = "ipAddress";
	public static final String NAME = "name";
	public static final String PUBLIC_KEY = "publicKey";
	public static final String PUBLIC_KEY_EXPIRES = "publicKeyExpires";
	public static final String TRANSPORT = "transport";
	public static final String PORTNO = "portno";
	public static final String LAST_CONNECT_TIME = "lastConnectTime";
	public static final String LAST_LOG_ID = "lastLogId";
	public static final String FORCE_THEME = "forceTheme";
	public static final String THEME = "theme";
	public static final String APPLICATIONID = "applicationid";

	public void save(MdlMnetHost transientInstance) {
		log.debug("saving MdlMnetHost instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlMnetHost persistentInstance) {
		log.debug("deleting MdlMnetHost instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlMnetHost findById(java.lang.Long id) {
		log.debug("getting MdlMnetHost instance with id: " + id);
		try {
			MdlMnetHost instance = (MdlMnetHost) getSession().get(
					"idv.loveloser.dao.MdlMnetHost", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlMnetHost instance) {
		log.debug("finding MdlMnetHost instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlMnetHost")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlMnetHost instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlMnetHost as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByDeleted(Object deleted) {
		return findByProperty(DELETED, deleted);
	}

	public List findByWwwroot(Object wwwroot) {
		return findByProperty(WWWROOT, wwwroot);
	}

	public List findByIpAddress(Object ipAddress) {
		return findByProperty(IP_ADDRESS, ipAddress);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByPublicKey(Object publicKey) {
		return findByProperty(PUBLIC_KEY, publicKey);
	}

	public List findByPublicKeyExpires(Object publicKeyExpires) {
		return findByProperty(PUBLIC_KEY_EXPIRES, publicKeyExpires);
	}

	public List findByTransport(Object transport) {
		return findByProperty(TRANSPORT, transport);
	}

	public List findByPortno(Object portno) {
		return findByProperty(PORTNO, portno);
	}

	public List findByLastConnectTime(Object lastConnectTime) {
		return findByProperty(LAST_CONNECT_TIME, lastConnectTime);
	}

	public List findByLastLogId(Object lastLogId) {
		return findByProperty(LAST_LOG_ID, lastLogId);
	}

	public List findByForceTheme(Object forceTheme) {
		return findByProperty(FORCE_THEME, forceTheme);
	}

	public List findByTheme(Object theme) {
		return findByProperty(THEME, theme);
	}

	public List findByApplicationid(Object applicationid) {
		return findByProperty(APPLICATIONID, applicationid);
	}

	public List findAll() {
		log.debug("finding all MdlMnetHost instances");
		try {
			String queryString = "from MdlMnetHost";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlMnetHost merge(MdlMnetHost detachedInstance) {
		log.debug("merging MdlMnetHost instance");
		try {
			MdlMnetHost result = (MdlMnetHost) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlMnetHost instance) {
		log.debug("attaching dirty MdlMnetHost instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlMnetHost instance) {
		log.debug("attaching clean MdlMnetHost instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}